package fun.shuofeng.juc.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author 朔风
 * @date 2024-02-29 21:05
 */
public class CompletableFutureApiDemo {
    public static void main(String[] args) throws InterruptedException {

        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return "success";
        });

        // TimeUnit.SECONDS.sleep(2);

        System.out.println(completableFuture.complete("faire"));
        System.out.println(completableFuture.join());


    }
}
